﻿using CPPEI.Coolzon.Common;
using CPPEI.Coolzon.Designer.Event.NCL;
using CPPEI.Coolzon.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CPPEI.Coolzon.Designer.Views
{
    public partial class LoginView
    {
        [Subscribe]
        public void EndLogin(EndLoginEvent @event)
        {
            if (@event.State == NCLEventState.Failure)
            {
                this.Dispatcher.Invoke(() =>
                {
                    CustomMessageBox.ShowError("登录失败，出现错误。", "错误");

                    _ctlBorderLogin.Visibility = System.Windows.Visibility.Visible;
                    _ctlBorderIndicator.Visibility = System.Windows.Visibility.Hidden;
                });
            }
            else if (@event.State == NCLEventState.Finished)
            {
                // 登录成功
                UIContext.Current.Token = @event.User.Token;
                UIContext.Current.ComputerName = System.Net.Dns.GetHostName();
                UIContext.Current.UserAccount = @event.User.UserAccount;
                UIContext.Current.UserName = @event.User.UserName;
                this.Dispatcher.Invoke(() =>
                {
                    _ctlBorderLogin.Visibility = System.Windows.Visibility.Visible;
                    _ctlBorderIndicator.Visibility = System.Windows.Visibility.Hidden;
                    this.DialogResult = true;
                });
            }
        }
    }
}
